from Crypto.Util.Padding import pad
from random import *
flag=b"123456789abcdef"

BLOCK=16
flag=pad(flag,BLOCK)
# print(len(flag))
def s_box(a):
    box=[i for i in range(a)]
    shuffle(box)
    return box
S_BOX=s_box(len(flag))
print(S_BOX)
m=[i for i in flag]
def swap(a,b):
    tmp = a
    a = b
    b = tmp
def encrypt1(m):
    enc=[m[i:i+BLOCK] for i in range(0,len(m),BLOCK)]
    for i in enc:
        for j in range(BLOCK):
            aa=j*7%BLOCK
            swap(i[j],i[aa])
encrypt1(m)
print("m",m)
def encrypt2(m):
    for i in range(16):
        m=[m[i] for i in S_BOX]
        # print(m)
    return m
c=encrypt2(m)
print(c)
k=0
while 1:
    c = encrypt2(c)
    k+=1
    if c[:8]==m[:8]:
        print(c[:8])
        print(k)
        break